package chunmap.raster.grid;

import java.util.Arrays;

import chunmap.data.feature.Raster;
import chunmap.model.elem.Envelope;
import chunmap.view.Renderer;
import chunmap.view.layer.AbstractLayer;
import chunmap.view.render.Symbol;

public class GridLayer extends AbstractLayer {

	private Grid[] grids;
	
	public Grid[] getGrids() {
		return grids;
	}

	public void setGrids(Grid[] grids) {
		Arrays.sort(grids);
		this.grids = grids;
	}

	@Override
	public void subRender(Symbol smb,int i, Renderer r) {
		if(grids==null || grids.length==0)
			return;
		
		Grid grid=findGrid(r);
		for(Raster tile:grid.getTiles()){
			r.draw(tile, smb,i);
		}
	}
	
	private Grid findGrid(Renderer r){
		double scale=r.getScale();
		for(Grid grid:grids){
			if(grid.getScale()>=scale){
				return grid;
			}
		}
		return grids[grids.length-1];
	}

	@Override
	public Envelope getEnvelop() {
		// TODO Auto-generated method stub
		return null;
	}
	
	public void setEnvelop(Envelope env) {
		// TODO Auto-generated method stub
	}
}
